package com.maoslv.utils;

import com.maoslv.pojo.Menu;

import java.util.ArrayList;
import java.util.List;

public class TreeUtil {
    public static List<Menu> toTree(List<Menu> menus) {
        List<Menu> treeList = new ArrayList<>();
        for (Menu menu : menus) {
            for (Menu e : menus) {
                if (menu.getId() == e.getParentId()) {
                    menu.getChild().add(e);
                }
            }

            if (menu.getParentId() == 0) {
                treeList.add(menu);
            }
        }
        return treeList;
    }
}
